<template>
  <div class="pagination">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
    />
  </div>
</template>

<script>
export default {
  name: 'PaginationVue',
  data() {
    return {
      page: {
        total: 10,
        pageSize: 10,
        currentPage: 1,
      },
    };
  },
  props: ['pageData'],
  watch: {
    pageData: {
      handler(newVal) {
        this.page = newVal;
      },
      deep: true,
    },
  },
  methods: {
    // 每页条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.page.pageSize = val;
      this.$emit('getData', this.page);
    },

    // 当前页
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.$emit('getData', this.page);
    },
  },
};
</script>

<style scoped lang="less">
.pagination {
  display: flex;
  justify-content: center;
  position: absolute;
  bottom: 16px;
  left: 30%;
}
</style>
